﻿using Apache.NMS.ActiveMQ.Util.Synchronization;
using Minio;

namespace CommonUtils
{
    public static class MinioUtil
    {
        public static MinioClient BuildClient(string host, int port, string key, string pwd, bool ssl = false)
        => new MinioClient().WithEndpoint(host, port).WithCredentials(key, pwd).WithSSL(ssl).Build();

        public static void Upload(this MinioClient minio, string path, string bucket, string objectName)
        {
            LogUtil.log("正在上传文件[{}]至minio...\r\nbucket: {}, objectName: {}", path, bucket, objectName);
            minio.PutObjectAsync(new PutObjectArgs().WithBucket(bucket).WithObject(objectName).WithFileName(path)).GetAsyncResult();
            LogUtil.log("{} 已上传至minio\r\nbucket: {}, objectName: {}", path, bucket, objectName);
        }
    }
}
